//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int n, m, a[1000], i, j, x, y, z, s, d;

bool o(){
	s=0, d=1;
	for(i=0;i<n&&d<=m;++i){
		if(s+a[i]<=y){
			s+=a[i];
		}
		else {
			++d;
			s=a[i];
		}
	}
	return d<=m && i<=n;
}

int main (){
	//freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);
	while(scanf("%d%d",&n, &m)==2){
		y=x=z=0;
		for(i=0;i<n;++i){
			scanf("%d", &a[i]);
			x=x<a[i]?a[i]:x;
			z+=a[i];
		}
		y=(x+z)/2;
		while(x<z){
			if(o())	z=y;
			else	x=y+1;
			y=(x+z)/2;
			//printf("%d %d %d\n", x, y, z);
		}
		printf("%d\n",y);
		
		
	}
	return 0;
}
